<template>
  <el-form ref="form" :model="filterForm" label-width="80px" :inline="true">
    <el-form-item label="设备名称" prop="strDevicename">
      <el-input v-model="filterForm.strDevicename" placeholder="请输入设备名称" class="inptw200" />
    </el-form-item>
    <el-form-item label="设备码" prop="strGrantdevicenum">
      <el-input v-model="filterForm.strGrantdevicenum" placeholder="请输入设备码" class="inptw200" />
    </el-form-item>
    <el-form-item label="所属机构" prop="iOrgsysnum">
      <el-cascader
        v-model="filterForm.iOrgsysnum"
        :show-all-levels="false"
        :options="iOrgOptions"
        :props="{ expandTrigger: 'hover',value:'strOrgnum',label:'strOrgname',children: 'yhlist', checkStrictly: true }"
      />
    </el-form-item>
    <el-form-item label="设备状态" prop="iStatus">
      <el-select v-model="filterForm.iStatus" placeholder="请选择设备状态">
        <el-option
          v-for="item in deviceIStatus"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click.native.prevent="handleSearch">查询</el-button>
      <el-button @click="$refs['form'].resetFields()">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { beforeList, mqsend } from '@/api/devices/index'
export default {
  name: 'FilterForm',
  props: {
    iOrgOptions: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      filterForm: {
        strDevicename: '',
        strGrantdevicenum: '',
        iStatus: '',
        strOrgname: '',
        iOrgsysnums: this.$store.getters.iOrgsysnum,
        pagenum: 1,
        type: 1

      },
      deviceIStatus: [
        {
          label: '在线已部署',
          value: 1
        },
        {
          label: '离线已部署',
          value: 2
        },
        {
          label: '离线未部署',
          value: 3
        }
      ]
    }
  },
  methods: {
    handleSearch() {
      mqsend(this.filterForm)
      this.$parent.$data.loading = true
      setTimeout(() => {
        beforeList(this.filterForm).then(res => {
          this.$parent.tableData = res && res.data
          this.$parent.total = !res.total ? 0 : res.total
          this.$parent.$data.loading = false
        }).catch(err => {
          console.log(err)
        })
      }, 3000)
    }
  }
}
</script>
